package com.lheia.jcb.spider

import common.HttpMesConstants
import grails.converters.JSON

class UrlProcessController {
    def urlProcessCreate(){}
    def urlProcessIndex(){}
    def urlProcessService
    /**
     * 爬虫记录列表显示
     */
    def urlProcessQuery() {
        def dataMap = urlProcessService.urlProcessQuery(params)
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, count: dataMap.total, data: dataMap.data] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_DATA_NULL] as JSON)
        }
    }
    /**
     * 爬虫记录详情
     * @return
     */
    def getUrlProcessDataMap() {
        def dataMap = urlProcessService.getUrlProcessDataMap(params.long('urlProcessId'))
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, data: dataMap] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_DATA_NULL] as JSON)
        }
    }

    /**
     * 爬虫记录保存
     * @return
     */
    def urlProcessSave() {
        def dataMap = urlProcessService.urlProcessSave(params)
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, msg: HttpMesConstants.MSG_SAVE_OK, data: dataMap] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_SAVE_FAIL] as JSON)
        }
    }

    /**
     * 爬虫记录删除
     * @return
     */
    def urlProcessDel() {
        def dataMap = urlProcessService.urlProcessDel(params.long('urlProcessId'))
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, msg: HttpMesConstants.MSG_DEL_OK] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_DEL_FAIL] as JSON)
        }
    }

    /***
     * 上传文件表单
     * @return
     */
//    def resourceUpload(){
//        def resource = resourceService.upload(request, params)
//        if (resource){
//            render([code: HttpMesConstants.CODE_OK, msg: HttpMesConstants.MSG_UPLOAD_OK] as JSON)
//        } else {
//            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_UPLOAD_FAIL] as JSON)
//        }
//    }
}


